<template>
	<view class="myCommunityPage">
		<!-- <view class="searchContent">
			<u-input v-model="keyWord" shape="circle" inputAlign="center" placeholder="搜索" @confirm="doSearch">
				<view slot="suffix" class="iconClass" @click="doSearch">
					<u-icon name="search" color="#004DA1" size="52rpx"></u-icon>
				</view>
			</u-input>
		</view> -->
		<view class="listContent">
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" v-if="!list2.length && !isLoading"
				text="没有更多了"></u-empty>
			<view v-for="(item,index) in list2" :key="index" class="list">
				<view class="itemTop" @click="goDetail(item.id)">
					<view class="topRight">
						<u--image :src="item.images?(baseUrl+'/sys/common/static/'+item.images.split(',')[0]):''"
							shape="square" mode="aspectFill" width="208rpx" height="150rpx" bgColor="transparent"
							radius="8rpx">
						</u--image>
					</view>
					<view class="topLeft">
						<view class="title">{{item.name}}</view>
						<view class="talk">
							{{item.createTime}}
						</view>
					</view>
				</view>
				<view class="itemBottom">
					<view class="operate">
						<view class="item" @click="goDetail(item.id)">
							<u--image src="/static/community/4.png" shape="square" mode="aspectFill" width="30rpx"
								height="24rpx"></u--image>
							<view class="count">{{item.readingVolume||0}}</view>
						</view>
						<view class="item" @click="goDetail(item.id)">
							<u--image src="/static/community/5.png" shape="square" mode="aspectFill" width="26rpx"
								height="26rpx"></u--image>
							<view class="count">{{item.replyCount||0}}</view>
						</view>
						<view class="item" @click="goDetail(item.id)">
							<u--image src="/static/community/222.png" shape="square" mode="aspectFill" width="30rpx"
								height="24rpx" v-if="!item.isCollection"></u--image>
							<u--image src="/static/community/22.png" shape="square" mode="aspectFill" width="30rpx"
								height="24rpx" v-else></u--image>
							<view class="count">{{item.collection||0}}</view>
						</view>
						<view class="item" @click="goDetail(item.id)">
							<u--image src="/static/community/333.png" shape="square" mode="aspectFill" width="26rpx"
								height="26rpx" v-if="!item.isThumbsUp"></u--image>
							<u--image src="/static/community/33.png" shape="square" mode="aspectFill" width="26rpx"
								height="26rpx" v-else></u--image>
							<view class="count">{{item.thumbsUp||0}}</view>
						</view>
						<view class="item" @click="deleteItem(item)">
							<u--image src="/static/discuss/3.png" shape="square" mode="aspectFill" width="26rpx"
								height="26rpx"></u--image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore v-if="list2.length" :status="isFinish?'nomore':'loading'" loading-text="正在加载" loadmore-text="加载更多"
			nomore-text="没有更多了" color="#d0d0d0" />
		<u-popup :show="showDeleteMode" :round="10" mode="bottom" @close="doClose">
			<view class="midelPanel">
				<view class="title" @click="deleteData">删除</view>
				<view class="modelBtn" @click="showDeleteMode=false">
					<view class="btn">取消</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				iconClass: {
					color: "#004DA1",
					fontSize: "52rpx",
					borderLeft: "1rpx solid #D0D0D0",
					padding: "0 0 0 38rpx"
				},
				api: this.$api.baseUrl,
				list2: [],
				pageNo: 1,
				pageSize: 10,
				total: 0,
				isFinish: false,
				isLoading: false,
				userId: "",
				keyWord: "",
				baseUrl: this.$api.baseUrl,
				showDeleteMode: false,
				selectedData: ""
			}
		},
		onLoad() {
			uni.getStorage({
				key: "userInfo",
				success: (userInfo) => {
					this.userId = userInfo.data.id;
					this.initData();
				}
			})
		},
		onReachBottom() {
			if (!this.isLoading && !this.isFinish) {
				this.pageNo++;
				this.initData();
			}
		},
		onPullDownRefresh() {
			this.doSearch()
		},
		methods: {
			doClose() {
				this.showDeleteMode = false
			},
			deleteItem(item) {
				this.selectedData = item.id;
				this.showDeleteMode = true
			},
			deleteData() {
				this.$request.delete(this.$api.deletePost + "?id=" + this.selectedData).then(res => {
					this.showDeleteMode = false;
					this.doSearch(true)
					uni.hideLoading()
				})
			},
			doSearch(tag) {
				this.isFinish = false;
				if (!this.isLoading) {
					this.pageNo = 1;
					this.list2 = [];
					this.initData(true,tag);
				}
			},
			goDetail(id) {
				uni.navigateTo({
					url: "/pages/postDetail/postDetail?id=" + id
				})
			},
			initData(isRefresh,tag) {
				this.isLoading = true;
				this.$request.get(this.$api.myPosts, {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					userId: this.userId,
					name: this.keyWord
				}).then(res => {
					if (isRefresh) {
						uni.stopPullDownRefresh()
					}
					this.isLoading = false;
					this.list2 = this.list2.concat(res.result.records)
					this.total = res.result.total;
					if (this.pageNo * this.pageSize < this.total) {
						this.isFinish = false
					} else {
						this.isFinish = true
					}
					if(tag){
						uni.showToast({
							icon: 'success',
							title: "删除成功"
						})
					}
					uni.hideLoading()
				})
			},
		}
	}
</script>

<style lang="scss">
	.myCommunityPage {
		.searchContent {
			padding: 0rpx 40rpx 26rpx;
			background-color: #FAFAFA;

			.iconClass {
				border-left: 1rpx solid #D0D0D0;
				padding: 0 0 0 38rpx;
			}
		}

		.listContent {

			display: flex;
			flex-direction: column;
			padding: 20rpx 40rpx;

			.list {
				display: flex;
				flex-direction: column;
				padding: 30rpx 20rpx 24rpx;
				background: #FFFFFF;
				box-shadow: inset 0px 0px 0px 1rpx rgba(230, 230, 230, .5);
				border-radius: 10px 10px 10px 10px;
				margin-bottom: 20rpx;

				.itemTop {
					display: flex;
					flex-wrap: nowrap;
					justify-content: flex-start;
					padding-bottom: 20rpx;

					.topLeft {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						width: 100%;

						.title {
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #333333;
							font-size: 28rpx;
							letter-spacing: 1rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 3;
							-webkit-box-orient: vertical;
							padding-right: 20rpx;
						}

						.talk {
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							font-size: 26rpx;
						}
					}

					.topRight {
						flex-shrink: 0;
						padding-right: 20rpx;
					}
				}

				.itemBottom {
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					font-size: 26rpx;

					.operate {
						display: flex;
						flex-wrap: nowrap;
						justify-content: space-between;
						width: 100%;

						.item {
							display: flex;
							flex-wrap: nowrap;
							align-items: center;
							padding-right: 40rpx;

							.count {
								padding-left: 10rpx;
							}
						}
					}
				}
			}
		}

		.midelPanel {
			display: flex;
			text-align: center;
			flex-direction: column;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				height: 100rpx;
				line-height: 100rpx;
			}

			.cost {
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				display: flex;
				flex-wrap: nowrap;
				justify-content: center;
				border-bottom: 1rpx solid #eee;
				height: 100rpx;
				line-height: 100rpx;
			}

			.modelBtn {
				display: flex;
				justify-content: center;
				padding-top: 20rpx;
				padding-bottom: 20rpx;

				.btn {
					height: 92rpx;
					line-height: 92rpx;
					width: 680rpx;
					font-size: 32rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					text-align: center;
					background: #F6F6F6;
					border-radius: 48rpx;
				}
			}

		}
	}
</style>
